export const baseUrl = 'http://localhost:9007';

import request from "./request";

// 发送验证码
export function sendCode(mobile) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl+`/user-service/user/code/${mobile}`,
			method: "GET",
			success(res) {
				console.log('响应拦截器succeess接口返回:', res)
			},
			fail(err) {
				reject(err)
			},
			complete() {
				uni.hideLoading()
			}
		})
	})
}

// 登录
export function login(mobile, code) {
	const loginData = {
		mobile: mobile,
		code: code
	};
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl+`/user-service/user/login`,
			method: "POST",
			data: loginData,
			success(res) {
				resolve(res.data)
				console.log('响应拦截器succeess接口返回:', res)
			},
			fail(err) {
				reject(err)
			},
			complete() {
				uni.hideLoading()
			}
		})
	})
}

//获取个人信息
export function getUserDetail(userId) {
	return request(`/user-service/user/${userId}`, "GET")

}


export function getRank(userId) {
	return request(`/task-service/task/rank/${userId}`, "GET")
}

// 接受工单
export function acceptTask(taskId) {
	return request(`/task-service/task/accept/${taskId}`, "GET")
}

// 拒绝/取消工单
export function cancelTask(taskId, cancelTaskDto) {
	return request(`/task-service/task/cancel/${taskId}`, "POST", cancelTaskDto)
}

// 完成工单
export function completeTask(taskId) {
	return request(`/task-service/task/complete/${taskId}`, "GET")

}


export function searchTasks(params) {
	return request(`/task-service/task/search`, "GET", params)
}

export function getByTaskId(taskId) {
	return request(`/task-service/task/${taskId}`, "GET")
}